<?php
namespace Home\Controller;
use Think\Controller;
class CommonController extends Controller {
    public function log($info=''){

    	$data['create_time'] =time();
    	$data['content'] = serialize($info);

    	M('log')->add($data);
       
    }

    public function wCurl($info,$id)
    {
    	$data = array(
    		'key'=>'facc47b9f3afc7a493121bf6aacab53f',
    		'info'=>$info,
    		'userid'=>$id
    		);
	    //初始化
	    $ch = curl_init();
	    //设置选项，包括URL
	    curl_setopt($ch, CURLOPT_URL, "http://www.tuling123.com/openapi/api");
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($ch, CURLOPT_HEADER, 0);
	    curl_setopt($ch, CURLOPT_POST, 1);
	    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

	    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		    'Content-Type: application/json')
		);
	    //执行并获取HTML文档内容
	    $output = curl_exec($ch);
	    //释放curl句柄
	    curl_close($ch);
	    //打印获得的数据
	    return json_decode($output,true);
    }
    /**
     * [wget curl模拟get方式请求数据]
     * @Author   Xuebingsi
     * @DateTime 2017-02-08T12:01:07+0800
     * @param    [type]                   $url [请求路径]
     * @return   [type]                        [请求返回的数据，转数组]
     */
    public function wget($url)
    {

    	// var_dump($url);
	    //初始化
	    $ch = curl_init();
	    //设置选项，包括URL
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($ch, CURLOPT_HEADER, 0);
	    //https
	    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	    //执行并获取HTML文档内容
	    $output = curl_exec($ch);

	    // var_dump($output);
	    //释放curl句柄
	    curl_close($ch);
	    //打印获得的数据
	    return json_decode($output,true);
    }

    /**
     * [wpost curl模拟post请求]
     * @Author   Xuebingsi
     * @DateTime 2017-02-08T12:01:54+0800
     * @param    [type]                   $url  [post路径]
     * @param    [type]                   $data [post数据]
     * @return   [type]                         [请求返回的数据，转数组]
     */
     public function wpost($url, $data)
    {
    	// var_dump(json_encode($data,JSON_UNESCAPED_UNICODE));
	    //初始化
	    $ch = curl_init();
	    //设置选项，包括URL
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    curl_setopt($ch, CURLOPT_HEADER, 0);
	    curl_setopt($ch, CURLOPT_POST, 1);
	    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,JSON_UNESCAPED_UNICODE));

	    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		    'Content-Type: application/json')
		);
		//https
	    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	    //执行并获取HTML文档内容
	    $output = curl_exec($ch);
	    var_export($output);
	    //释放curl句柄
	    curl_close($ch);
	    //打印获得的数据
	    return json_decode($output,true);
    }
}